﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SOEN341_SCHEDULER_PHASE1
{
    public partial class ui_form_add_constraint : Form
    {
        public ui_form_add_constraint()
        {
            InitializeComponent();
        }
        #region "save" button functionality
        private void button1_Click(object sender, EventArgs e)
        {
            // make sure weekday, start time, end time are not empty or null.

            // get day, time
            int startHour = ui_dtp_startTime.Value.Hour;
            int endHour = ui_dtp_endTime.Value.Hour;
            int startMinute = ui_dtp_startTime.Value.Minute;
            int endMinute = ui_dtp_endTime.Value.Minute;
            
            
            // create a list
            List<DayOfWeek> dayOfTheWeek = new List<DayOfWeek>();
            DayOfWeek cwd = DayOfWeek.Monday;
            DayOfWeek selectedDay = DayOfWeek.Monday;
            // convert selectedDay from string to list item
            try
            {
                cwd = (DayOfWeek)ui_cmbx_weekday.SelectedItem;    
                
                // add selectedDay to dayOfTheWeek
                dayOfTheWeek.Add(cwd);

                // create a new CDT object
                CustomDateTime constraintTime = new CustomDateTime(startHour, startMinute, endHour, endMinute, dayOfTheWeek);

                List<DayOfWeek> ret = constraintTime.GetDayOfWeek();
                DayOfWeek temp;
                for (int i = 0; i < ret.Count; i++)
                {
                    temp = ret[i];
                }

                // create a new constraint

                Constraint ctemp = GlobalVariablesClass.session_loggedInStudent.GetConstraints();
                ctemp.AddConstraint(constraintTime);
            }
            catch(Exception dayException)
            {
                MessageBox.Show(dayException.ToString());
            }
            
            
        }
        #endregion

        #region "save and add" button functionality
        private void button2_Click(object sender, EventArgs e)
        {
            // make sure weekday, start time, end time are not empty or null.

            // get hour, minute, day
            int startHour = ui_dtp_startTime.Value.Hour;
            int endHour = ui_dtp_endTime.Value.Hour;
            int startMinute = ui_dtp_startTime.Value.Minute;
            int endMinute = ui_dtp_endTime.Value.Minute;
            string selectedDay = ui_cmbx_weekday.Text;

            // create a list
            List<DayOfWeek> dayOfTheWeek = new List<DayOfWeek>();

            // convert selectedDay from string to list item, add to dayOfTheWeek
            dayOfTheWeek.Add((DayOfWeek)Enum.Parse(typeof(DayOfWeek), selectedDay));

            // create a new CDT object
            CustomDateTime constraintTime = new CustomDateTime(startHour, startMinute, endHour, endMinute, dayOfTheWeek);
 
            // create a new constraint
            // AddConstraint(constraintTime);

            // clear, reload form somehow...
        }
        #endregion

        private void ui_form_add_constraint_Load(object sender, EventArgs e)
        {
            InitControls();
        }

        private void InitControls()
        {
            ui_cmbx_weekday.Items.Add(DayOfWeek.Monday);
            ui_cmbx_weekday.Items.Add(DayOfWeek.Tuesday);
            ui_cmbx_weekday.Items.Add(DayOfWeek.Wednesday);
            ui_cmbx_weekday.Items.Add(DayOfWeek.Thursday);
            ui_cmbx_weekday.Items.Add(DayOfWeek.Friday);
        }

        private void ui_form_add_constraint_FormClosed(object sender, FormClosedEventArgs e)
        {
            GlobalVariablesClass.ui_main_form_login.Enabled = true;
        }

        private void ui_cmbx_weekday_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

    }
}
